#include "dkglLog.h"
#include <fstream>
#include <time.h>

namespace DKGL
{

using namespace std;

string Log::mFileName("dkglLog.txt");

void Log::dump(const std::string& reason)
{
#ifdef DKGL_ENABLE_LOG
	ofstream fout(mFileName.c_str(), ios::out | ios::app);
	time_t current_time;
	time(&current_time);
	char *ptr = ctime(&current_time);
	fout << "Log@ "<< string(ptr);
	fout << "  "<< reason << endl;
	fout.close();
#endif
}

void Log::dump(const std::string& reason, const std::string& src_fname, int src_line, ERROR_LEVEL level)
{
#ifdef DKGL_ENABLE_LOG
	//if(!mBeEnable)
	//	return;

	ofstream fout(mFileName.c_str(), ios::out | ios::app);
	time_t current_time;
	time(&current_time);
	char *ptr = ctime(&current_time);
		
	fout << "==================================" << endl;

	if(level==ERR_ERROR)
		fout <<"Error@"<< string(ptr);
	else if(level==ERR_WARNING)
		fout << "Warning@" << string(ptr);

	fout << "file : " << src_fname << endl;
	fout << "line : " << src_line << endl;
	fout << "msg : " << reason << endl;
	fout.close();
#endif
}

void Log::clear()// const
{
	ofstream fout(mFileName.c_str(), ios::out);
	fout.close();
}

}